import request, { download } from '@/utils/request'

// 查询自身培训列表
export function listTrain(query) {
  return request({
    url: '/train/list',
    method: 'get',
    params: query
  })
}

// 查询自身培训详细
export function getTrain(trainId) {
  return request({
    url: '/train/' + trainId,
    method: 'get'
  })
}

// 新增培训
export function addTrain(data) {
  return request({
    url: '/train',
    method: 'post',
    data: data
  })
}

//查询培训类型
export function queryTrainType() {
  return request({
    url: '/train/queryTrainType',
    method: 'get'
  })
}

// 删除培训
export function delTrain(trainId) {
  return request({
    url: '/train/' + trainId,
    method: 'delete'
  })
}

// 指定人员查询培训列表
export function masterListTrain(query) {
  return request({
    url: '/train/masterList',
    method: 'get',
    params: query
  })
}

// 指定人员查询培训详细
export function masterGetTrain(trainId) {
  return request({
    url: '/train/master/' + trainId,
    method: 'get'
  })
}

// 指定人员审核培训
export function masterApproval(data) {
  return request({
    url: '/train/masterApproval',
    method: 'post',
    data: data
  })
}

// 查询自身培训列表
export function ownTrainList(query) {
  return request({
    url: '/train/ownTrainList',
    method: 'get',
    params: query
  })
}

// 管理员个人培训Excel详情
export function ownExcelInfo(userId) {
  return request({
    url: '/train/ownExcelInfo/' + userId,
    method: 'get'
  })
}

// 管理员导出所选项
export function adminExport(ids) {
  return request({
    url: '/train/adminExport',
    method: 'post',
    data: ids
  }).then(function(r) {
    if (r.code == '200') {
      window.open(process.env.VUE_APP_BASE_API + 'common/download?fileName=' + r.msg + '&delete=true')
    }
  })
}

//获取部门
export function getDept() {
  return request({
    url: '/train/getDept/',
    method: 'get'
  })

}
